package com.itheima.sh.service.impl;

import com.itheima.sh.dao.UserMapper;
import com.itheima.sh.exception.ExceptionCast;
import com.itheima.sh.pojo.User;
import com.itheima.sh.response.ResponseResult;
import com.itheima.sh.response.StatusCode;
import com.itheima.sh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public Boolean add(User user) {
        if (user.getUserName()==null){
            ExceptionCast.cast(ResponseResult.errorResult(StatusCode.APUSER_USERNAMEISNULL_ERROR ));
        }
        return userMapper.add(user);
    }
}
